﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace HZ.Supervise.Web.Master
{
    public partial class MasterPageSecond : System.Web.UI.MasterPage
    {
        string strhid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(Request.QueryString["hid"]))
            {
                strhid = Request.QueryString["hid"].ToString();
                if (strhid.Contains("Y"))  //医院
                {
                    rblcompanytype.Visible = false;
                    if (strhid.Length > 1)
                    {
                        txtname.Text = strhid;
                    }
                    bangdingHostial();
                }
                if (strhid.Contains("JS"))  //企业
                {
                    rblcompanytype.Visible = true ;
                    if (strhid.Length > 2)
                    {
                        txtname.Text = strhid;
                    }
                    bangdingCompany();
                }
            }
          
        }

        protected void gvwselect_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ("医院" == "医院")
                {
                    e.Row.Cells[0].Text = "<a href='ReportOfHospitalFirstLevel.aspx?hid="+e.Row.Cells[1].Text+"' target='_self'>" + e.Row.Cells[0].Text + "</a>";
                }
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if ("医院" == "医院")
                {
                    gvwselect.Columns[0].HeaderText = "医院名称";
                }
            }
        }

        protected void gvwselect_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvwselect.PageIndex = e.NewPageIndex;
            gvwselect.DataBind(); 
        }

        /// <summary>
        /// 绑定医院
        /// </summary>
        private void bangdingHostial()
        {
            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            string _HospitalID = txtname.Text.Trim();
            if (_HospitalID.Equals(""))
            {
                _HospitalID = "所有医院";
            }
            lbname.Text = "医院名称";
            int t = 0;
            DataTable dt = pre.GetHospitalName(_HospitalID,1,0,out t);
            DataColumn dac = new DataColumn("databf", typeof(string));
            DataColumn dacid = new DataColumn("databfid", typeof(string));
            dt.Columns.Add(dac); dt.Columns.Add(dacid);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["databf"] = dt.Rows[i]["HospitalName"];
                dt.Rows[i]["databfid"] = dt.Rows[i]["HospitalID"];
            }
            gvwselect.DataSource = dt;
            gvwselect.DataBind();
        }

        /// <summary>
        /// 绑定企业
        /// </summary>
        private void bangdingCompany()
        {

            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            string _CompanyID = txtname.Text.Trim();
            if (_CompanyID.Equals(""))
            {
                _CompanyID = "所有企业";
            }
            lbname.Text = "企业名称";
            int totalrecord = 0;
            DataTable dt = pre.GetCompanyName(_CompanyID, rblcompanytype.SelectedValue,1,0,out totalrecord);
            DataColumn dac = new DataColumn("databf", typeof(string));
            DataColumn dacid = new DataColumn("databfid", typeof(string));
            dt.Columns.Add(dac); dt.Columns.Add(dacid);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["databf"] = dt.Rows[i]["CompanyName"];
                dt.Rows[i]["databfid"] = dt.Rows[i]["CompanyID"];
            }
            gvwselect.DataSource = dt;
            gvwselect.DataBind();
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {

        }

        protected void rblcompanytype_SelectedIndexChanged(object sender, EventArgs e)
        {
            bangdingCompany();
        }
        
    }
}
